﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static MonitorPrism_Practice.EnumData.KeyBoardMouseVlaueCollection;

namespace MonitorPrism_Practice.Services
{
    public interface IkeyBoardMouseClickService
    {
       public Dictionary<Enum_KeyBoardButton, bool> KeyMoniterCollection { get; }
     public Dictionary<Enum_MouseButton, bool> MouseMoniterCollection { get;  }

        Queue<Action> DispatchQueue { get; }//键盘鼠标消息调度队列

        bool DispatchMouseButton(Enum_MouseButton mouseButton);

        bool DispatchKeyBoardButton(Enum_KeyBoardButton keyBoardButton);

        void KeyBoardMouseEueue(Action action);
    }

    public class KeyBoardMouseClickManager : IkeyBoardMouseClickService
    {
        private readonly Dictionary<Enum_KeyBoardButton, bool> _keyMoniterCollection = new();
        private readonly Dictionary<Enum_MouseButton, bool> _mouseMoniterCollection = new();
        private Queue<Action> actions = new();

        public Queue<Action> DispatchQueue => actions;

        public Dictionary<Enum_KeyBoardButton, bool> KeyMoniterCollection => _keyMoniterCollection;

        public Dictionary<Enum_MouseButton, bool> MouseMoniterCollection => _mouseMoniterCollection;

        public KeyBoardMouseClickManager() 
        {
            foreach (Enum_KeyBoardButton item in Enum.GetValues(typeof(Enum_KeyBoardButton)))
            {
                if (KeyMoniterCollection.ContainsKey(item))
                {
                    KeyMoniterCollection[item] = false;
                }
                else
                {
                    KeyMoniterCollection.Add(item, false);
                }
            }
            foreach (Enum_MouseButton item in Enum.GetValues(typeof(Enum_MouseButton)))
            {
                if (MouseMoniterCollection.ContainsKey(item))
                {
                    MouseMoniterCollection[item] = false;
                }
                else
                {
                    MouseMoniterCollection.Add(item, false);
                }
            }
        }

        public bool DispatchKeyBoardButton(Enum_KeyBoardButton keyBoardButton)
        {
            return KeyMoniterCollection[keyBoardButton];
        }

        public bool DispatchMouseButton(Enum_MouseButton mouseButton)
        {
            return MouseMoniterCollection[mouseButton];
        }

        public void KeyBoardMouseEueue(Action action)
        {
            DispatchQueue.Enqueue(action);
        }
    }
}
